package io.renren.modules.examination.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.Constant;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.examination.dao.ExaminationQuestionsDao;
import io.renren.modules.examination.entity.ExaminationQuestionsEntity;
import io.renren.modules.examination.service.ExaminationQuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("examinationQuestionsService")
public class ExaminationQuestionsServiceImpl extends ServiceImpl<ExaminationQuestionsDao, ExaminationQuestionsEntity> implements ExaminationQuestionsService {

    @Autowired
    ExaminationQuestionsDao examinationQuestionsDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<ExaminationQuestionsEntity> page = this.selectPage(
                new Query<ExaminationQuestionsEntity>(params).getPage(),
                new EntityWrapper<ExaminationQuestionsEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPageByPaperId(Map<String, Object> params, Integer paperId) {
        PageUtils page=new PageUtils();
        int total=examinationQuestionsDao.getExaminationQuestionsTotalByPaperId(params, paperId);
        page.setPageSize(Integer.parseInt((String) params.get("limit")));
        page.setList(examinationQuestionsDao.getExaminationQuestionsListByPaperId(params, paperId));
        page.setTotalCount(total);
        page.setCurrPage(Integer.parseInt((String) params.get("page")));
        page.setTotalPage(Constant.getTotalPage(page.getTotalCount(),page.getPageSize()));
        return page;
    }

    @Override
    public PageUtils getExaminationQuestionsList(Map<String, Object> params) {
        PageUtils page=new PageUtils();
        int total=examinationQuestionsDao.getExaminationQuestionsTotal(params);
        page.setPageSize(Integer.parseInt((String) params.get("limit")));
        page.setList(examinationQuestionsDao.getExaminationQuestionsList(params));
        page.setTotalCount(total);
        page.setCurrPage(Integer.parseInt((String) params.get("page")));
        page.setTotalPage(Constant.getTotalPage(page.getTotalCount(),page.getPageSize()));
        return page;
    }

}
